<template>
  <link rel="stylesheet" href="/assets/css/poster.css">
  <div class="content">
  <div class="poster">
      <van-image id="poster" :src="business.poster_text"/>
  </div>

  <div class="link">
      <input type="text" id="url" readonly v-model="business.url" />
      <van-button @click="copy" type="default" id="btn">点击复制</van-button>
  </div>
  </div>

  <div class="update">
      <van-button @click="update" type="primary" id="update">重新生成海报</van-button>
  </div>
</template>

<script setup>
    const {proxy} = getCurrentInstance()

    let business = proxy.$business

    const update = async ()=>
    {
       //组装数据
       var params = {
            busid:business.value.id,
        }

        var result = await proxy.$UPLOAD({
            url:'/team/poster',
            params
        })
        
        
        if(result.code == 1)
        {
          proxy.$success({
                message: result.msg,
                duration: 500,
                onClose: ()=>{
                    proxy.$business.value.poster_text = result.data.poster
                }
                
            })
        }else
        {
            proxy.$fail(result.msg)
        }
    }

    const copy = async () =>
    {
        var url = document.getElementById('url');

        url.select()

        document.execCommand("copy".false)
    }
</script>